package com.itheima.service;

import com.itheima.pojo.Comment;
import com.itheima.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {
    @Autowired
    CommentRepository commentRepository;
    public Comment get(String id) {
        return  commentRepository.findById(id).get();
    }

    public List<Comment> getAll() {
        return commentRepository.findAll();
    }

    public void save(Comment comment) {
        commentRepository.save(comment);
    }

    public void update(Comment comment) {
        commentRepository.save(comment);
    }

    public  List<Comment> getArticle(String articleId) {
          List<Comment> comments= commentRepository.findByArticleid(articleId);
         return comments;
    }

    public void thumbup(String id) {
        Comment comment = commentRepository.findById(id).get();
        comment.setThumbup( comment.getThumbup()+1);
        commentRepository.save(comment);
    }
}
